package com.atguigu.java;
class window1 implements Runnable {
    private int tick = 100;

    //    Object obj=new Object();
    @Override
    public void run() {

        while (true) {
//            synchronized (this) {

            show();
        }
    }

    //}
    public synchronized void show() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        if (tick > 0) {
            System.out.println(Thread.currentThread().getName() + "买票，票号为" + tick);
            tick--;
        }
    }
}

public class WindowTest2 {
    public static void main(String[] args) {


        window1 w =new window1();
        Thread T1=new Thread(w);
        Thread T2=new Thread(w);
        Thread T3=new Thread(w);
        T1.setName("窗口1");
        T2.setName("窗口2");
        T3.setName("窗口3");
        T1.start();
        T2.start();
        T3.start();
    }

}
